# bash completion for domination-license-updater
# Устанавливается в /usr/share/bash-completion/completions/domination-license-updater

_domination_license_updater()
{
    local cur prev
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # Параметры, принимающие значение: файлы дополняем, остальное оставляем пользователю.
    case "$prev" in
        -f|--file|--input|-o|--output)
            COMPREPLY=( $(compgen -f -- "$cur") )
            return 0
            ;;
        --id|--answer)
            return 0
            ;;
    esac

    if [[ $COMP_CWORD -eq 1 ]]; then
        COMPREPLY=( $(compgen -W "cli --help --version" -- "$cur") )
        return 0
    fi

    # Всё остальное имеет смысл только внутри консольного режима.
    if [[ "${COMP_WORDS[1]}" != "cli" ]]; then
        return 0
    fi

    if [[ $COMP_CWORD -eq 2 ]]; then
        COMPREPLY=( $(compgen -W "list info question apply version help --help --version" -- "$cur") )
        return 0
    fi

    local opts
    case "${COMP_WORDS[2]}" in
        list)     opts="--json" ;;
        info)     opts="--id --json" ;;
        question) opts="--id --output --force" ;;
        apply)    opts="--id --file --answer" ;;
        *)        opts="" ;;
    esac

    COMPREPLY=( $(compgen -W "$opts --help" -- "$cur") )
}

complete -F _domination_license_updater domination-license-updater
